﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Threading;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace NetwerkScanner
{
    public class ExtendedServiceSet : INotifyPropertyChanged 
    {

        public BasicServiceSetCollection BasicServiceSets { get; set; }
        public HostCollection Hosts { get; set; }
        public string SSID { get; set; }

        public ConnectivityChart Chart { get; set; }

        public int RSSI
        {
            get
            {
                int lowest = -100;
                foreach (BasicServiceSet bss in BasicServiceSets)
                {
                    if (bss.RSSI > lowest && bss.LastUpdate.AddSeconds(10) > DateTime.Now)
                    {
                        lowest = bss.RSSI;
                    }
                }
                return lowest;
            }
        }

        public DateTime LastUpdate
        {
            get
            {
                DateTime best = DateTime.Today;
                foreach (BasicServiceSet bss in BasicServiceSets)
                {
                    if (bss.LastUpdate > best)
                    {
                        best = bss.LastUpdate;
                    }
                }
                return best;
            }
        }

        public ExtendedServiceSet(string id)
        {
            SSID = id;
            BasicServiceSets = new BasicServiceSetCollection();
            Hosts = new HostCollection();
        }

        public bool Active()
        {
            foreach (BasicServiceSet bss in BasicServiceSets)
            {
                if (bss.LastUpdate.AddSeconds(10) > DateTime.Now)
                {
                    return true;
                }
            }
            return false;
        }


        public void ChangeProperty(string s)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(s));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Hulp klasse voor treeview databinding
        /// </summary>
        public sealed class BasicServiceSetCollection : ObservableCollection<BasicServiceSet>
        {
            public override string ToString()
            {
                return "Access Points";
            }
        }

        /// <summary>
        /// Hulp klasse voor treeview databinding
        /// </summary>
        public sealed class HostCollection : ObservableCollection<Host>
        {
            public override string ToString()
            {
                return "Hosts";
            }
        }

    }
}
